# from fastapi import FastAPI
from models import Customer
import configparser


def load_config():
    config = configparser.ConfigParser()
    config.read('config.ini')
    return config['database']

config = load_config()

from database import get_all_customers
# app = FastAPI()


# @app.get("/customers/{page}")
# async def get_customers_by_page(page: int):
#     return get_customers_by_page(page)



from typing import Any, Union

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def read_root():
    return {"database": config["database"]}

@app.get("/config")
async def read_root():
    return {"connString":  f"mssql+pymssql://{config['username']}:{config['password']}@{config['host']}:{config['port']}/{config['database']}"}


@app.get("/items/{item_id}")
async def read_item(item_id: int, q: Union[str, None] = None):
    return {"item_id": item_id, "q": q}

@app.get("/customers", response_model=list[Customer])
async def read_customers() -> Any:
    # return[
    #     {"id": "123", "name": "John"},
    #     {"id": "456", "name": "Jane"}
    # ]
    mylist = get_all_customers()
        # for customer in mylist:
        #     print(customer)
    return mylist
                      